$("#form-customerInfo-edit").validate({
	rules:{
		name:{
			required:true,
		},
		cellphone:{
			required:true,
		},
		identityNum:{
			required:true,
		}
	},
	submitHandler:function(form){
		edit();
	}
});

function edit() {
	var backgroundName=$("select[name='backgroundId'] option:selected").text();
	var cellphone = $("input[name='cellphone']").val();
	var phoneNum = $("input[name='phoneNum']").val();
	var identityNum = $("input[name='identityNum']").val();
	
	var myreg=/^[1][3,4,5,7,8][0-9]{9}$/; //手机号码
	var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证号码 
	
	if(!myreg.test(cellphone)){
		layer.msg('请输入正确的手机号码')
		return false
	}else if(!reg.test(identityNum)){
		layer.msg('请输入正确的身份证号码')
		return false
	}else{
		_ajax_save(ctx + "module/customerInfo/save?backgroundName="+backgroundName, $('#form-customerInfo-edit').serialize());
	}
}

$(function() {
	var html = "";
	$("#input_city").append(html);
	$("#input_area").append(html);
	$.each(pdata, function(idx, item) {
		if (parseInt(item.level) == 0) {
			html += "<option value='" + item.names + "' exid='" + item.code
					+ "'>" + item.names + "</option>";
		}
	});
	$("#input_province").append(html);
	$("#input_province").change(
			function() {
				if ($(this).val() == "")
					return;
				$("#input_city option").remove();
				$("#input_area option").remove();
				var code = $(this).find("option:selected").attr("exid");
				code = code.substring(0, 2);
				var html = "<option value=''>--请选择--</option>";
				$("#input_area").append(html);
				$.each(pdata, function(idx, item) {
					if (parseInt(item.level) == 1
							&& code == item.code.substring(0, 2)) {
						html += "<option value='" + item.names + "' exid='"
								+ item.code + "'>" + item.names + "</option>";
					}
				});
				$("#input_city").append(html);
			});
	$("#input_city").change(
			function() {
				if ($(this).val() == "")
					return;
				$("#input_area option").remove();
				var code = $(this).find("option:selected").attr("exid");
				code = code.substring(0, 4);
				var html = "<option value=''>--请选择--</option>";
				$.each(pdata, function(idx, item) {
					if (parseInt(item.level) == 2
							&& code == item.code.substring(0, 4)) {
						html += "<option value='" + item.names + "' exid='"
								+ item.code + "'>" + item.names + "</option>";
					}
				});
				$("#input_area").append(html);
			});
});

